home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / text / hyper / ADtoHT2_0.lha / MyLib.lha / stdlib / realloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-03  |  608 b   |  34 lines

  1. #include "stdlib.h"
  2. #include "string.h"
  3.  
  4. #include <proto/exec.h>
  5.  
  6. /************************************************************************/
  7.  
  8. void *realloc(void *Memory, size_t Size)
  9.  
  10. {
  11.   unsigned long *NewMemory;
  12.  
  13.   NewMemory=NULL;
  14.   if (Size)
  15.     {
  16.       if (!(NewMemory=malloc(Size)))
  17.     {
  18.       return NULL;
  19.     }
  20.       if (Memory)
  21.     {
  22.       size_t CopySize;
  23.  
  24.       CopySize=(*(((unsigned long *)Memory)-1) < *(NewMemory-1)) ? *(((unsigned long *)Memory)-1) : *(NewMemory-1);
  25.       CopyMemQuick(Memory,NewMemory,CopySize-sizeof(unsigned long));
  26.     }
  27.     }
  28.   if (Memory)
  29.     {
  30.       free(Memory);
  31.     }
  32.   return NewMemory;
  33. }
  34.